'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 查询BOSS战当前状态
 * @author agl
 */

var async = require('async');
var _ = require('lodash');
var Code = require('../../../../consts/code');
var unionBossModel = require('../../../../models/unionBossModel.js');
var PlayerManager = require('../../../../libs/playerManager.js');

/**
 * 查询累计伤害奖励
 */
module.exports = function (msg, session, next) {
    var role_id = session.uid;

    var result = {};
    var player_manager = new PlayerManager(role_id);
    async.waterfall(
        [
            function (cb) {
                player_manager.refreshData(cb);
            },
            function (cb) {
                player_manager.getModel(['role', 'role_union_boss'], cb);
            },
            function (cb) {
                var role_model = player_manager.role;
                var role_union_boss_model = player_manager.role_union_boss;

                var union_id = role_model.union_id;
                if (union_id === 0) {
                    return next(null, {
                        code: Code.UNION_IS_NOT_JOIN
                    });
                }

                result.total_damage = role_union_boss_model.total_damage;
                result.picked_total_damage_reward = role_union_boss_model.picked_total_damage_reward;

                cb();
            }
        ],
        function (err) {
            if (!!err) {
                console.error(err);
                return next(null, {
                    code: Code.FAIL
                });
            }
            return next(null, {
                code: Code.OK,
                result: result
            });
        }
    );
};
